<?php
/**
 * Created by PhpStorm.
 * User: zjw
 * Date: 2018/3/8
 * Time: 下午4:00
 */
use common\models\Coupon;
use kartik\datetime\DateTimePicker;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\CouponCategory;

$categoryList = CouponCategory::find()->all();
$categoryArr = [];
foreach ($categoryList as $key => $category) {
    $categoryArr[$category->mark_id] = $category->title;
}
?>

<?php
$paraString = explode('?', Yii::$app->request->url)[1];
?>
<div class="article-index">
    <div class="coupon-search">
    <?php $form = ActiveForm::begin([
        'method' => 'get',
//        'fieldConfig' => [
//            'template' => "<div class=\"col-lg-3\">{label}{input}</div>",
//        ],
        'options'=> ['class'=>'form-inline'],
    ]); ?>

    <?= $form->field($model, 'catalog_mark_id')->dropDownList(['' => '全部'] + $categoryArr)->label("分类") ?>
        <div class="form-group">
            <?= Html::submitButton('搜索', ['class' => 'btn btn-primary center']) ?>
            <?= Html::a('同步领取状态',['sync'], ['class' => 'btn btn-success center']) ?>
        </div>
    <?php ActiveForm::end(); ?>
    </div>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'origin_id',
            'code',
//            'origin_num',
//            'use_num',
            ['attribute'=>'status','value'=>function($model){
                return $model->status?'可用':'已用';
            }],
            'catalog_mark_id',
            'name',
            [
                'attribute' => 'catalog',
                'value' => function ($model) {
                    return $model->couponCategory->title;
                }
            ],
            [
                'attribute' => 'created_at',
                'value' => function ($model) {
                    return date('Y-m-d H:i:s', $model->created_at);
                }
            ],
            [
                'attribute' => 'updated_at',
                'value' => function ($model) {
                    return date('Y-m-d H:i:s', $model->updated_at);
                }
            ],
            [
                'attribute' => 'expire_at',
                'value' => function ($model) {
                    return date('Y-m-d', $model->expire_at);
                }
            ],
            'desc',
            ['class' => 'yii\grid\ActionColumn',
                'template' => '{update} {delete} {url}'
            ],
        ],
    ]); ?>
</div>